package it.xiuxian.personcenter.activity

import com.alibaba.android.arouter.facade.annotation.Route
import it.xiuxian.lib.base.ArouterAddress
import it.xiuxian.lib.base.BaseActivity
import it.xiuxian.personcenter.R
import it.xiuxian.lib.bean.ContentBean
import it.xiuxian.personcenter.databinding.ActivityAboutUsBinding
import it.xiuxian.personcenter.presenter.AboutUsActivityPresenter
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.content.Intent
import android.content.res.ColorStateList
import android.net.Uri
import android.os.Build
import androidx.annotation.RequiresApi
import it.xiuxian.lib.utils.ToastUtil


@Route(path = ArouterAddress.ABOUTUSACTIVITY)
class AboutUsActivity:BaseActivity<AboutUsActivityPresenter>() {
    private var cm: ClipboardManager? = null
    private var mClipData: ClipData? = null
    var binding:ActivityAboutUsBinding?=null
    override val layoutId: Int
        get() = R.layout.activity_about_us
    override val presenter: AboutUsActivityPresenter
        get() = AboutUsActivityPresenter()


    @RequiresApi(Build.VERSION_CODES.M)
    override fun initView() {
        setTitle("联系客服")
      binding =getViewDataBinding<ActivityAboutUsBinding>()
       /* binding!!.include.tvTitle.setTextColor(getColor(R.color.libTextWhite))
        binding!!.include.leftImg.imageTintList = ColorStateList.valueOf(getColor(R.color.libTextWhite))*/
        mPresenter!!.aboutUs()
        //获取剪贴板管理器：
        cm = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager?;
       // binding!!.tvContent.setText("")
    }

    override fun initData() {
        mPresenter!!.aboutUs()
    }

    override fun initEvent() {
       // super.initEvent()
        binding!!.llFuzhi.setOnClickListener {
            callPhone(phone)

        }
        binding!!.llPhone.setOnClickListener {
            mClipData = ClipData.newPlainText("Label", email)
            // 将ClipData内容放到系统剪贴板里。
            cm!!.setPrimaryClip(mClipData!!)
            ToastUtil.showShort("复制成功");

        }
    }
   lateinit var email:String
    lateinit var phone:String
    fun setUI(data: ContentBean) {
        binding!!.tvContent.text = "邮箱:"+data.email
        binding!!.tvContent1.text ="电话号:"+data.phone
        email = data.email
        phone = data.phone
    }
    fun callPhone(phoneNum: String) {
        val intent = Intent(Intent.ACTION_DIAL)
        val data: Uri = Uri.parse("tel:$phoneNum")
        intent.setData(data)
        startActivity(intent)
    }
}